import router from './router/index';
import { getToken, getSiderBar } from '@/utils/public';

import store from './store/index';
const whiteList = ['/login'];
router.beforeEach((to, from, next) => {
  let token = getToken();
  if (token) {
    next();
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next();
    } else {
      next('/login');
    }
  }
});

router.afterEach((to) => {
  if (to.path !== getSiderBar()) {
    store.commit('SET_BAR', to.path);
  }
});
